package com.project.ssmfo.controller.common;

import java.io.BufferedReader;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.StringReader;
import java.util.HashMap;
import java.util.Map;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.project.ssmfo.common.Configuration;
import com.project.ssmfo.controller.BaseController;
import com.project.utils.FileUtils;


@Controller
public class FileViewController extends BaseController{
	
	/**
	 * <p>Title: downloadFile</p>
	 * <p>Description: 下载图片附件</p>
	 * @param moduleName
	 * @param fileDate
	 * @param fileName
	 * @param upfile void
	 */
	@RequestMapping("/fileView/{moduleName}/{fileDate}/{fileName}.{fileType}")
	@ResponseBody
	public void downloadFile(
			 @PathVariable String moduleName,  
			 @PathVariable String fileDate,
			 @PathVariable String fileName,
			 @PathVariable String fileType
			){
		String baseStoreDir = Configuration.get("file_savedir");
		String storePath = baseStoreDir + "/" + moduleName+"/"+fileDate;
		FileUtils.downFile(getHttpResponse(), storePath, fileName + "." + fileType, fileName + "." + fileType);
	}
	
	/**
	 * <p>Title: downloadFile</p>
	 * <p>Description: 下载图片附件</p>
	 * @param moduleName
	 * @param fileDate
	 * @param fileName
	 * @param upfile void
	 */
	@RequestMapping("/fileView/{unitNo}/{moduleName}/{fileDate}/{fileName}.{fileType}")
	@ResponseBody
	public void downloadFile2(
			 @PathVariable String unitNo,
			 @PathVariable String moduleName,  
			 @PathVariable String fileDate,
			 @PathVariable String fileName,
			 @PathVariable String fileType
			){
		String baseStoreDir = Configuration.get("file_savedir");
		String storePath = baseStoreDir + "/"+unitNo+"/" + moduleName+"/"+fileDate;
		FileUtils.downFile(getHttpResponse(), storePath, fileName + "." + fileType, fileName + "." + fileType);
	}
	

}
